﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace pufflesweb
{
    public partial class help : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PModel.User mysuer = new PModel.User();

                mysuer = (PModel.User)PF.SessionHelper.GetSession("user");
                
                this.HiddenField1.Value = mysuer.UID.ToString();
                
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            PModel.HApply happly = new PModel.HApply();
            PModel.User myuser = new PModel.User();
            myuser = (PModel.User)PF.SessionHelper.GetSession("user");
            happly.User = myuser;
            //happly.User.UID = int.Parse(this.uid.Text);
            //happly.User.UID = int.Parse(this.HiddenField1.Value);
            happly.HAdogname = this.hadogname.Text.Trim();
            happly.HAage = int.Parse(this.haage.Text.Trim());
            happly.HAstate = int.Parse(this.hastate.Text.Trim());
            happly.HAsex = int.Parse(this.hasex.Text.Trim());
            happly.HAvaccine = int.Parse(this.havaccine.Text.Trim());
            happly.HAphone = int.Parse(this.haphone.Text.Trim());
            happly.HAqq = int.Parse(this.haqq.Text.Trim());
            happly.HAtext = this.hatext.Text.Trim();
            happly.HAname = this.haname.Text.Trim();
            happly.HAaddress = this.haaddress.Text.Trim();
            happly.HAwechat = this.hawechat.Text.Trim();
            happly.HAemail = this.haemail.Text.Trim();

            if (haimage.HasFile)
            {
                string filename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + Path.GetExtension(haimage.FileName);
                string filePath = "~/images/happlyimg/" + filename;
                haimage.SaveAs(MapPath(filePath));
                happly.HAimage = filename;
            }

            if (PBLL.HApply.add(happly))
            {
                PF.JsHelper.AlertAndParentUrl("修改保存成功", "index.aspx");
            }
            else
            {
                PF.JsHelper.AlertAndParentUrl("修改失败,请重新输入", "tables.aspx");
            }
        }
        
    }
}